package FLS.Controller;

import java.util.Date;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;

import FLS.DataAccessObjects.ArtikelDao;
import FLS.Model.Artikel;

@Controller
public class ArtikelController {
	private static Logger log = Logger.getLogger(ArtikelController.class);
	private ArtikelDao artikelDao = null;

	public void setArtikelDao(ArtikelDao artikelDao) {
		this.artikelDao = artikelDao;
	}

	/**
	 * <p>
	 * Artikel form request.
	 * </p>
	 * 
	 * <p>
	 * Expected HTTP GET and request '/index.html'.
	 * </p>
	 * 
	 * @return
	 */
	@RequestMapping(value = "/index.html", method = RequestMethod.GET)
	public ModelAndView edit(@RequestParam(required = false) Integer id) {
		log.debug("index.html");
		ModelAndView mv = new ModelAndView();
		Authentication auth = SecurityContextHolder.getContext().getAuthentication();
		if (id == null) {
			mv.addObject(new Artikel());
		} else {
			mv.addObject(artikelDao.findById(id));
		}
		mv.setViewName("index");
		return mv;
	}

	

}
